<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/26 0026
 * Time: 下午 16:42
 */

namespace app\admin\controller;

use app\admin\model\ProductTypes as A;

class ProductTypes extends Common
{
    private $PageTitle ;
    //实例化model
    protected $db;
    protected function _initialize()
    {
        parent::_initialize();
        $this->db=new A();
    }
    /*
    *分类数组
    */
    public function getTypeData()
    {
        $arr= $this->db->getAllData();

        $this->assign('arr',$arr);
    }
   public function index()
   {

       $this->getTypeData();
      $this->PageTitle='产品分类页';
      $this->generalInfor($this->PageTitle);
       return $this->fetch();
   }
    public function add()
    {
        $arr=$this->db->getTypeDataAll();
        $this->assign('arr',$arr);
        $this->PageTitle='产品分类添加';
        $this->generalInfor($this->PageTitle);

        if(request()->isPost())
        {
            //halt($_POST);
            $type_add=new A();
            $res=$type_add->type_add(input('post.'));
            $mess=array(
                'status'=>$res['valid'],
                'message'=>$res['msg']
            );
            return $mess;
        }
        return $this->fetch();
    }
    public function getPareArr()
    {
        $id=input('param.id');
        $res=$this->db->getPareArr($id);
        echo json_encode($res);
    }
    //修改
    public function edit()
    {
        $res=$this->db->getTypeDataAll();
        $this->assign('res',$res);
        $this->getTypeData();
        $this->PageTitle='商品分类修改';
        $this->generalInfor($this->PageTitle);
        $id=input('param.id');
        $arr=$this->db->getOneInfo($id);
        $this->assign('arr',$arr);
        $this->generalInfor($this->PageTitle);
        if(request()->isPost())
        {
            //halt($_POST);
            $res=$this->db->edit_type(input('post.'));
            $mess=array(
                'status'=>$res['valid'],
                'message'=>$res['msg']
            );
            return $mess;
        }
        return $this->fetch();
    }
    //下架
    public function shelf()
    {
        $res=$this->db->shelf(input('param.'));
        $mess = array(
            'status' => $res['valid'],
            'message' => $res['msg']
        );
        return $mess;
    }

}